﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Services.Description;

namespace Cake_Management.Controllers
{
    public class HT_SizeController : Controller
    {
        // GET: HT_Size
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult GetAll()
        {
            var result = new BLL.B_Size().GetAll();

            var aa = from s in result
                     select new
                     {
                         s.Id,
                         GoodsId=s.Goods.GoodsName,
                         s.Size1,
                         s.Price,
                         ss= $"<div class='btn btn-warning data-Edit'data-id='{s.Id}'onclick='Edit(this)'>编辑</div>   <div class='btn btn-danger data-del' data-id='{s.Id}' onclick='Delete(this)'>删除</div>"
                     };
            var data=new {data=aa};
            return Json(data,JsonRequestBehavior.AllowGet);
        }

        [HttpGet]
        public ActionResult Add()
        {
            ViewBag.goods=new BLL.B_Goods().GetAll();
            return PartialView();
        }

        [HttpPost]
        public ActionResult Add(Size size)
        {
            new BLL.B_Size().Add(size);
            return Json(new {Code=200,Message="添加成功"});
        }

        [HttpPost]
        public ActionResult Delete(int id)
        {
            new BLL.B_Size().Delete(id);
            return Json(new { Code = 200, Message = "删除成功" });
        }

        [HttpGet]
        public ActionResult Edit(int id)
        {
            ViewBag.goods=new BLL.B_Goods().GetAll();
            var data=new BLL.B_Size().FindById(id);
            return PartialView(data);
        }

        [HttpPost]
        public ActionResult Edit(Size size)
        {
            new BLL.B_Size().Updata(size.Id, size);
            return Json(new { Code = 200, Message = "修改成功" });
        }
    }
}